<template>
	<view>
		<u-card padding="16" v-for="(item,index) in dataList" :key="index">
			<view class="" slot="head">
				<view class="wrap">
					<u-row>
						<u-col span="12" text-align="left">
							<view class=" u-m-t-2 weikaishi3 lanse">
								<span>收货单位：{{item.getUnit}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="12" text-align="left">
							<view class="weikaishi5">
								<span><u-icon name="map" size="29" labelSize="14px" labelColor="#00c300" label="地址"></u-icon>：{{item.getLocation}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="6" text-align="left">
							<view class=" u-m-t-2 weikaishi4">
								<span>配置：{{item.tooVolume}}m³</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class=" u-m-t-2 weikaishi4">
								<span>件数：{{item.tooNum}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
			<view class="" slot="body">
				<view class="wrap">
					<view v-for="(item2,index2) in item.list" :key="index2">
						<u-row>
							<u-col span="10" text-align="left">
								<view class="u-line-1 u-m-t-10 weikaishi4">
									<span>单号：{{item2.customerOrder}}</span>
								</view>
							</u-col>
							<u-col span="2" text-align="right" @click="delOeder(item2)">
								<view class="u-line-1 u-m-t-10">
									<u-icon name="trash" label-color="#dd6161" color="#dd6161" size="40"></u-icon>
								</view>
							</u-col>
						</u-row>
						<u-collapse>
							<u-collapse-item :title="'配置'+item2.tooVolume+'m³，件数'+item2.tooNum">
								<view v-for="(item3,index3) in item2.listd" :key="index3">
									<u-row>
										<u-col span="10" text-align="left">
											<view class="">
												<span>{{item3.goodsName}}</span>
											</view>
										</u-col>
										<u-col span="1" text-align="center" @click="editGoods(item3)">
											<view class="">
												<u-icon name="edit-pen" label-color="#2b85e4" color="#2b85e4" size="35"></u-icon>
											</view>
										</u-col>
										<u-col span="1" text-align="right" @click="delGoodid(item3)">
											<view class="">
												<u-icon name="trash" label-color="#dd6161" color="#dd6161" size="30"></u-icon>
											</view>
										</u-col>
										<u-col span="6" text-align="left">
											<view class="u-line-1">
												<span>体积：{{item3.tooDeployVolume}}m³</span>
											</view>
										</u-col>
										<u-col span="6" text-align="right">
											<view class="u-line-1">
												<span>数量：{{item3.tooDeployNum}}</span>
											</view>
										</u-col>
									</u-row>
									<u-row>
										<u-col span="12" text-align="left">
											<view class="u-m-t-25">
											</view>
										</u-col>
									</u-row>
								</view>
							</u-collapse-item>
						</u-collapse>
					</view>
				</view>
			</view>
		</u-card>
		<u-popup v-model="show" mode="center" closeable width="680rpx" height="550rpx" border-radius="5">
			<view class="u-text-center u-m-t-20 weikaishi3"><u-icon name="order" size="30" labelSize="15px" labelColor="#000000" :label="'单号：'+showcustomerOrder"></u-icon></view>
			<u-card padding="16">
				<view class="" slot="head">
					<view class="wrap">
						<u-row>
							<u-col span="12">
								<view class="weikaishi3 lanse">
									<span>{{edititem.goodsName}}</span>
								</view>
							</u-col>
						</u-row>
					</view>
				</view>
				<view class="" slot="body">
					<view class="wrap">
						<u-row>
							<u-col span="3" text-align="center">
								<view class="weikaishi u-m-t-10">
									<span>体积</span>
								</view>
							</u-col>
							<u-col span="2" text-align="center">
								<view class="weikaishi u-m-t-10">
									<span>数量</span>
								</view>
							</u-col>
							<u-col span="3" text-align="center">
								<view class="weikaishi u-m-t-10 lanse">
									<span>配置体积</span>
								</view>
							</u-col>
							<u-col span="4" text-align="center">
								<view class="weikaishi u-m-t-10 lanse">
									<span>配置数</span>
								</view>
							</u-col>
						</u-row>
						<u-row>
							<u-col span="3" text-align="center">
								<view class="u-m-t-10 weikaishi4">
									<span>{{edititem.transportPutvolume}}</span>
								</view>
							</u-col>
							<u-col span="2" text-align="center">
								<view class="u-m-t-10 weikaishi4">
									<span>{{edititem.num}}</span>
								</view>
							</u-col>
							<u-col span="3" text-align="center">
								<view class="u-m-t-10 weikaishi4">
									<span>{{edititem.tooDeployVolume}}</span>
								</view>
							</u-col>
							<u-col span="4" text-align="center">
								<view class="u-m-t-2 weikaishi6 yiwancheng">
									<span><u-input v-model="edititem.tooDeployNum" type="digit" border="true" height="50" placeholder=" " @input="chaidaninput"/></span>
								</view>
							</u-col>
						</u-row>
					</view>
				</view>
			</u-card>
			<view style="height: 80rpx;text-align: center;">
				<view class="close-btn u-m-t-40">
					<u-button size="medium" @click="define()">确定</u-button>
				</view>
			</view>
		</u-popup>
		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList:[],
				edititem:{
					id:'',
					carnumbger:'',
					transportPutvolume:'',
					num:'',
					tooDeployVolume:'',
					tooDeployNum:'',
					goodsName:'',
					goodsVolume:''
				},
				showcustomerOrder:'',
				show:false,
			}
		},
		onLoad() {
			this.refresh()
		},
		methods: {
			define(){
				if(this.edititem.tooDeployNum == ''){
					uni.showToast({
						title: "请输入数值",
						icon: 'none'
					})
					return
				}
				if(typeof parseFloat(this.edititem.tooDeployNum) != 'number' ||  parseFloat(this.edititem.tooDeployNum) <= 0){
					uni.showToast({
						title: "请输入正确数值",
						icon: 'none'
					})
					return
				}
				if(parseFloat(this.edititem.tooDeployNum) > parseFloat(this.edititem.num)){
					uni.showToast({
						title: "超出订单数量",
						icon: 'none'
					})
					return
				}
				uni.showLoading({
					title: '正在提交'
				})
				this.$http.post('/rest/transport/editGoods',{
				},{
					params: this.edititem,
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					uni.hideLoading()
					if(res.data.code == 200) {
						this.show = false
						this.$refs.uToast.show({
							title: '操作成功',
							type: 'success'
						})
						setTimeout(() => {
							this.refresh()
						}, 500)
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'error'
						})
						setTimeout(() => {
							this.refresh()
						}, 500)
					}
				})
			},
			chaidaninput(e){
				if(typeof parseFloat(e) != 'number' ||  parseFloat(e) <= 0){
					uni.showToast({
						title: "请输入正确数值",
						icon: 'none'
					})
					return
				}
				if(parseFloat(e) > parseFloat(this.edititem.num)){
					uni.showToast({
						title: "超出订单数量",
						icon: 'none'
					})
					return
				}
				this.edititem.tooDeployVolume  = (e*this.edititem.goodsVolume).toFixed(3)
			},
			editGoods(item){
				this.showcustomerOrder = item.customerOrder
				this.edititem.id = item.id
				this.edititem.carnumbger = item.carnumbger  
				this.edititem.transportPutvolume = item.transportPutvolume
				this.edititem.num = item.num
				this.edititem.tooDeployVolume = item.tooDeployVolume
				this.edititem.tooDeployNum = item.tooDeployNum
				this.edititem.goodsName = item.goodsName
				this.edititem.goodsVolume = item.goodsVolume
				this.show = true
			},
			delGoodid(item){
				uni.showModal({
					content: '确定移除商品吗？',
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								title: '正在提交'
							})
							this.$http.post('/rest/transport/removeGoods',{
							},{
								params: {
									transportNumber: item.transportNumber,
									goodsId: item.goodsId,
									carnumbger:uni.getStorageSync('check_carnumbger')
								},
								header: {
									'Authorization' :uni.getStorageSync('token'),
								}
							}).then(res => {
								uni.hideLoading()
								if(res.data.code == 200) {
									this.$refs.uToast.show({
										title: '操作成功',
										type: 'success'
									})
									setTimeout(() => {
										this.refresh()
									}, 500)
								} else {
									this.$refs.uToast.show({
										title: res.data.message,
										type: 'error'
									})
									setTimeout(() => {
										this.refresh()
									}, 500)
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			delOeder(item){
				uni.showModal({
					content: '确定移除订单吗？',
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								title: '正在提交'
							})
							this.$http.post('/rest/transport/removeOrder',{
							},{
								params: {
									transportNumber: item.transportNumber,
									carnumbger:uni.getStorageSync('check_carnumbger')
								},
								header: {
									'Authorization' :uni.getStorageSync('token'),
								}
							}).then(res => {
								uni.hideLoading()
								if(res.data.code == 200) {
									this.$refs.uToast.show({
										title: '操作成功',
										type: 'success'
									})
									setTimeout(() => {
										this.refresh()
									}, 500)
								} else {
									this.$refs.uToast.show({
										title: res.data.message,
										type: 'error'
									})
									setTimeout(() => {
										this.refresh()
									}, 500)
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			refresh(){
				this.$http.post('/rest/transport/listOrder',{
				},{
					params: {
						carnumbger:uni.getStorageSync('check_carnumbger')
					},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					this.dataList = res.data.data
				})
			},
		}
	}
</script>


<style lang="scss">
	.u-body-item {
		padding: 20rpx 15rpx;
	}
	.wrap {
		padding: 0rpx 12rpx;
	}
	.u-row {
		margin: 10rpx 2rpx;
	}
	.weikaishi2{
		font-size: 34rpx;
	}
	.baise{
		color: #ffffff;
		font-size: 34rpx;
	}
</style>
